class WeiboController < ApplicationController

  def index
    result = Account.access_weibo(params[:code])
    if result[0]
      if result[1] == "admin"
        redirect_to '/' and return # /admin
      else
        session[:current_user] = result[1]
        cookies[:flowy_token] = result[1]
        redirect_to '/' and return
      end
    else
      render :text => result[1]
    end
  end

  # def search
  #   # TODO 参数检查
  #   options = {
  #     :pagesize => params[:pagesize],
  #     :page => params[:page],
  #     :sorttype => params[:sorttype],
  #     :msgtype => params[:msgtype],
  #     :searchtype => params[:searchtype],
  #     :starttime => params[:starttime],
  #     :endtime => params[:endtime],
  #     :province => params[:province],
  #     :city => params[:city]
  #   }
  #   render :json => Utility::Weibo.search(params[:keyword], options)
  # end

  # def create
  #   params[:weibos] ||= {:wid => ["3444517204329764"]}
  #   params[:comment] ||= "测试啊测试"
  #   # @current_user = {"access_token" => "2.00dkJ6tCih7QHDa1168ae0b4Zve7gB"
  #   @current_user ||= Account.find_or_create_by(:access_token_weibo => "2.00dkJ6tCih7QHDa1168ae0b4Zve7gB")
  #   result = params[:weibos].map do |weibo|
  #     @current_user.create_comment(Account::WEIBO,
  #                                 params[:comment],
  #                                 weibo[:wid],
  #                                 weibo[:wuid])
  #   end
  #   render :json => result
  # end

  ##### private #####

end
